package com.tc.minio;

import com.alibaba.fastjson.JSONObject;
import io.minio.ListObjectsArgs;
import io.minio.MinioClient;
import io.minio.Result;
import io.minio.errors.*;
import io.minio.messages.Item;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Iterator;

/**
 * @Auther: tianchao
 * @Date: 2021/8/18 23:20
 * @Description:
 */
public class ObjectList {
    public static void main(String[] args) throws IOException, InvalidKeyException, InvalidResponseException, InsufficientDataException, NoSuchAlgorithmException, ServerException, InternalException, XmlParserException, ErrorResponseException {
        MinioClient minioClient = MinioFactory.getMinioClient();
        // Iterable<Result<Item>> dockerminio = minioClient.listObjects(ListObjectsArgs.builder().bucket("dockerminio").recursive(true).delimiter("/").build());
        Iterable<Result<Item>> dockerminio = minioClient.listObjects(ListObjectsArgs.builder().bucket("dockerminio").build());
        Iterator<Result<Item>> iterator = dockerminio.iterator();
        while (iterator.hasNext()){
            Item item = iterator.next().get();
            System.out.println(item.objectName());
            System.out.println(item.size());
            System.out.println(item.userMetadata());
            System.out.println("===============================");
        }
    }
}
